thread: implement sleep_for on Windows Windows does not provide an implementation of `nanosleep`. Round up the time duration to the nearest ms and use `Sleep`. Although this may over-sleep, there is no hard real-time guarantee on the wake, so sleeping a bit more is better than under-sleeping as it within the specification. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291331 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/thread.cpp b/src/thread.cpp index 4fb1dd2..290e2ae 100644 --- a/src/thread.cpp +++ b/src/thread.cpp
@@ -117,6 +117,12 @@ using namespace chrono; if (ns > nanoseconds::zero()) { +#if defined(_LIBCPP_WIN32API) + milliseconds ms = duration_cast<milliseconds>(ns); + if (ns > duration_cast<nanoseconds>(ms)) + ++ms; + Sleep(ms.count()); +#else seconds s = duration_cast<seconds>(ns); timespec ts; typedef decltype(ts.tv_sec) ts_sec; @@ -134,6 +140,7 @@ while (nanosleep(&ts, &ts) == -1 && errno == EINTR) ; +#endif } }